package com.hcmus.armobile;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class RegisterActivity extends Activity {
	// alert dialog manager
	AlertDialogManager alert = new AlertDialogManager();
	
	// Internet detector
	ConnectionDetector cd;	
	
	// Register button
	Button btnRegister;
	Button btnUnRegister;
	Button btnSendMessage;  
	

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		//setContentView(R.layout.main);
		
		cd = new ConnectionDetector(getApplicationContext());

		// Check if Internet present
		if (!cd.isConnectingToInternet()) {
			// Internet Connection is not present
			alert.showAlertDialog(RegisterActivity.this,
					"Internet Connection Error",
					"Please connect to working Internet connection", false);
			// stop executing code by return
			return;
		}

		// Check if GCM configuration is set
		if (CommonUtilities.SERVER_URL == null || CommonUtilities.SENDER_ID == null || CommonUtilities.SERVER_URL.length() == 0
				|| CommonUtilities.SENDER_ID.length() == 0) {
			// GCM sernder id / server url is missing
			alert.showAlertDialog(RegisterActivity.this, "Configuration Error!",
					"Please set your Server URL and GCM Sender ID", false);
			// stop executing code by return
			 return;  
		}
				
	//	btnRegister = (Button) findViewById(R.id.btnRegister);  
		//btnUnRegister = (Button) findViewById(R.id.btnUnRegister);
		//btnSendMessage= (Button) findViewById(R.id.btnSendMessage);
		/*
		 * Click event on Register button
		 * */
		btnRegister.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				
				//Intent i = new Intent(getApplicationContext(), SendMessageActivity.class);
				//startActivity(i);
				//finish();
				
				// Read EditText dat
				
				// Check if user filled the form
				if(1==1){
					// Launch Main Activity
					Intent i = new Intent(getApplicationContext(), MainActivity.class);
					
					// Registering user on our server					
					// Sending registraiton details to MainActivity
					//i.putExtra("name", name);
					//i.putExtra("email", email);
					startActivity(i);
					finish();
				}else{
					// user doen't filled that data
					// ask him to fill the form
					alert.showAlertDialog(RegisterActivity.this, "Registration Error!", "Please enter your details", false);
				}
				
			}
		});
		
		btnUnRegister.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try{
					
					Intent i = new Intent(getApplicationContext(), UnRegister.class);					
					startActivity(i);
					finish();
				}catch(Exception ex){
					Log.w("Loi start activity un register", "Loi: "+ ex.toString());
				}
			}
		});
		
		btnSendMessage.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// TODO Auto-generated method stub
				try{
					
					Intent i = new Intent(getApplicationContext(), SendMessageActivity.class);					
					startActivity(i);
					finish();
				}catch(Exception ex){
					Log.w("Loi start activity send message", "Loi: "+ ex.toString());
				}
			}
		});
	}

}
